// 2013-9-26上午10:54:18  net.betou.trade.main.manager.impl.ShareMngImpl.java

package net.betou.trade.main.manager.impl;

import net.betou.common.page.Pagination;
import net.betou.common.util.DataConvertUtils;
import net.betou.trade.entity.main.AgentAndAdmins;
import net.betou.trade.main.dao.ContentDao;
import net.betou.trade.main.dao.NoticeDao;
import net.betou.trade.main.dao.TradeDao;
import net.betou.trade.main.manager.ShareMng;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 
 * @author 叶装装
 */
@Service
@Transactional
public class ShareMngImpl implements ShareMng{
	
	@Transactional( readOnly = true )
	public Pagination getNoticePage( AgentAndAdmins admin, String searchProperty, String searchValue, String orderProperty, String orderDirection, String filterStatus, int pageNo, int pageSize ){
		return noticeDao.getPage( getId( admin ), searchProperty, searchValue, orderProperty, orderDirection, filterStatus, pageNo, pageSize );
	}
	
	@Transactional( readOnly = true )
	public Pagination getOpenTradePage( AgentAndAdmins admin, String searchProperty, String searchValue, String orderProperty, String orderDirection, int pageNo, int pageSize, String filterStatus ){
		return tradeDao.getPage( true, getId( admin ), searchProperty, searchValue, orderProperty, orderDirection, pageNo, pageSize, filterStatus );
	}
	
	@Transactional( readOnly = true )
	public Pagination getCloseTradePage( AgentAndAdmins admin, String searchProperty, String searchValue, String orderProperty, String orderDirection, int pageNo, int pageSize, String filterStatus ) {
		return tradeDao.getPage( false, getId( admin ), searchProperty, searchValue, orderProperty, orderDirection, pageNo, pageSize, filterStatus );
	}
	
	@Transactional( readOnly = true )
	public Pagination getContentPage( AgentAndAdmins admin, String searchProperty, String searchValue, String orderProperty, String orderDirection, int pageNo, int pageSize ) {
		return contentDao.getPage( getId( admin ), searchProperty, searchValue, orderProperty, orderDirection, pageNo, pageSize );
	}
	
	private Integer getId( AgentAndAdmins admin ){
		Integer deep = admin.getDeep( );
		
		if( deep == 0 ){
			return admin.getId( );
		}
		
		return DataConvertUtils.getInt( StringUtils.split( admin.getTopIntermedia( ), "," )[ 0 ] );
	}
	
	@Autowired
	private NoticeDao noticeDao;
	
	@Autowired
	private TradeDao tradeDao;
	
	@Autowired
	private ContentDao contentDao;
}
